package com.spring.boot.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spring.boot.entity.*;
import com.spring.boot.response.Result;
import com.spring.boot.service.SysMenuService;
import com.spring.boot.service.SysRoleMenuService;
import com.spring.boot.service.SysRoleService;
import com.spring.boot.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@PreAuthorize("hasAnyRole('userOption')")
@RequestMapping("/userRole")
public class SysUserRoleController {
    @Autowired
    private SysUserRoleService userRoleService;

    @PostMapping("/add")
    public Result<?> save(@RequestBody SysUserRole userRole){
        userRoleService.save(userRole);//todo 要判断是否已存在
        return Result.OK("新增成功",userRole);
    }
//    @DeleteMapping("/delete/{id}")
//    public Result<?> deleteSysRole(@PathVariable int id){
//       sysRoleService.removeById(id);
//        return Result.OK("删除成功!", id);
//    }

    @PostMapping("/edit")
    public Result<?> updateSysUserRole(@RequestBody List<SysUserRole> userRoleList){
        userRoleService.updateByUserId(userRoleList);
        return Result.OK();
    }

}
